import request from '@/utils/request'

// 获取事件列表
export function getEvents(params) {
  return request({
    url: '/events',
    method: 'get',
    params
  })
}

// 订阅事件
export function subscribeEvent(deviceId, eventConfig) {
  return request({
    url: `/devices/${deviceId}/events/subscribe`,
    method: 'post',
    data: eventConfig
  })
}

// 取消订阅事件
export function unsubscribeEvent(deviceId, subscriptionId) {
  return request({
    url: `/devices/${deviceId}/events/unsubscribe/${subscriptionId}`,
    method: 'post'
  })
}

// 获取事件订阅列表
export function getEventSubscriptions(deviceId) {
  return request({
    url: `/devices/${deviceId}/events/subscriptions`,
    method: 'get'
  })
}

// 确认事件
export function acknowledgeEvent(eventId) {
  return request({
    url: `/events/${eventId}/acknowledge`,
    method: 'post'
  })
}

// 删除事件
export function deleteEvent(eventId) {
  return request({
    url: `/events/${eventId}`,
    method: 'delete'
  })
}

// 批量确认事件
export function batchAcknowledgeEvents(eventIds) {
  return request({
    url: '/events/batch/acknowledge',
    method: 'post',
    data: { eventIds }
  })
}

// 批量删除事件
export function batchDeleteEvents(eventIds) {
  return request({
    url: '/events/batch/delete',
    method: 'post',
    data: { eventIds }
  })
}

// 获取事件详情
export function getEventDetail(eventId) {
  return request({
    url: `/events/${eventId}`,
    method: 'get'
  })
}

// 搜索事件
export function searchEvents(searchParams) {
  return request({
    url: '/events/search',
    method: 'post',
    data: searchParams
  })
}

// 获取事件类型列表
export function getEventTypes() {
  return request({
    url: '/events/types',
    method: 'get'
  })
}

// 获取事件统计信息
export function getEventStats(params) {
  return request({
    url: '/events/stats',
    method: 'get',
    params
  })
}

// 获取实时事件（WebSocket连接信息）
export function getEventWebSocketInfo() {
  return request({
    url: '/events/websocket-info',
    method: 'get'
  })
}

// 设置事件配置
export function setEventConfig(deviceId, config) {
  return request({
    url: `/devices/${deviceId}/events/config`,
    method: 'put',
    data: config
  })
}

// 获取事件配置
export function getEventConfig(deviceId) {
  return request({
    url: `/devices/${deviceId}/events/config`,
    method: 'get'
  })
}

// 测试事件连接
export function testEventConnection(deviceId) {
  return request({
    url: `/devices/${deviceId}/events/test`,
    method: 'post'
  })
}

// 订阅设备事件
export function subscribeDeviceEvents(deviceId, eventConfig) {
  return request({
    url: `/devices/${deviceId}/events/subscribe`,
    method: 'post',
    data: eventConfig
  })
}

// 取消订阅设备事件
export function unsubscribeDeviceEvents(deviceId) {
  return request({
    url: `/devices/${deviceId}/events/unsubscribe`,
    method: 'post'
  })
}

// 批量订阅事件
export function batchSubscribeEvents(deviceIds, eventConfig) {
  return request({
    url: '/events/batch/subscribe',
    method: 'post',
    data: {
      deviceIds,
      eventConfig
    }
  })
}

// 批量取消订阅事件
export function batchUnsubscribeEvents(deviceIds) {
  return request({
    url: '/events/batch/unsubscribe',
    method: 'post',
    data: { deviceIds }
  })
}

// 批量获取事件订阅状态
export function batchGetEventSubscriptions(deviceIds) {
  return request({
    url: '/events/batch/subscriptions',
    method: 'post',
    data: { deviceIds }
  })
}

// 批量设置事件配置
export function batchSetEventConfig(deviceIds, config) {
  return request({
    url: '/events/batch/config',
    method: 'put',
    data: {
      deviceIds,
      config
    }
  })
}

// 批量测试事件连接
export function batchTestEventConnection(deviceIds) {
  return request({
    url: '/events/batch/test',
    method: 'post',
    data: { deviceIds }
  })
}